<?php 
	$id = $_GET['id']; 
	$jenis = $_GET['jenis'];
	
	$sql="select id_peserta, p.id_penduduk, nama, tempat_lahir, tgl_lahir from penduduk p inner join peserta pr on pr.id_penduduk = p.id_penduduk where p.id_penduduk='$id'";
	
	$qry=mysql_query($sql);
	$hasil = mysql_fetch_array($qry);
	
	//Masa berlaku surat jaminan
	$lama = mysql_fetch_array(mysql_query("select masa_berlaku from setting_waktu where id_setting = 2"));
?>
<script type="text/javascript" src="module/mod_jaminan/js/kode.js"></script>

<script type="text/javascript">
function hapusPerawatan(obj){	
	 if (confirm('Apakah data akan dihapus ?')) {
  		obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
	}
}
function add_data() {
        var tampil_tombol_aksi = '<a href="javascript:void(null)" title="Hapus" onclick="hapusPerawatan(this)"><img src="asset/images/button-delete.gif" alt="Hapus" border=0 /></a>';
  		var tr = document.createElement('tr');
  		var td_ruang = document.createElement('td');
		var td_tglmasuk = document.createElement('td');
		var td_tglkeluar = document.createElement('td');
  		var td_aksi = document.createElement('td');  		
  		var tbodi = document.getElementById("tbody_list_ruang");
  		
  		td_aksi.className = 'links';
  		td_aksi.width = 15;
  		td_ruang.innerHTML = "<select name='ruang2[]'>"+"<?php $ruang = mysql_query("select * from ruang"); 
		while($r = mysql_fetch_array($ruang)){ 
		$str_ruang.= "<option value=$r[id_ruang]>$r[ruang]</option>";
		} 
		echo $str_ruang;
		?>"+"</select>";
		td_tglmasuk.innerHTML = '<input type="text" name="tgl_masuk[]" class="tgl_rawat" size="10">';
		td_tglkeluar.innerHTML = '<input type="text" name="tgl_keluar[]" class="tgl_rawat" size="10">';

  		td_aksi.innerHTML = tampil_tombol_aksi;
  		
  		tr.appendChild(td_ruang);
		tr.appendChild(td_tglmasuk);
		tr.appendChild(td_tglkeluar);

  		tr.appendChild(td_aksi);
  		tbodi.appendChild(tr);
		
}
  
	$(document).ready(function(){
		$(".tgl_rawat").datepicker();
		$('#show').hide();
		$('#kunjungan').change(function(){
			if(this.checked)
				$('#show').hide('slow');
			else
				$('#show').show('slow');

		});
	});

	$(function() {
		$( "#datepicker1" ).datepicker();
	});
  
	$(function() {
		$( "#datepicker2" ).datepicker();
		
	});
</script>
<?php
	//Penomoran otomatis
	$tgl = date("my02");
	$query = "SELECT max(id_jaminan) as maxID FROM jaminan where id_jaminan like '$tgl%'";
	$kode = mysql_query($query);
	$data = mysql_fetch_array($kode);
	$idMax = $data['maxID'];
	$noUrut = (int) substr($idMax, 6, 4);
	$noUrut++;
	$newID = "$tgl".sprintf("%04s", $noUrut);
	if($jenis == 1){
?>
		<div id=tiga_ba>
			<div id=tiga_baa>Tambah Jaminan Rawat Jalan</div>
			<div id=tiga_bab></div>
			<div class=clear></div>
		</div>
		<form action="utama.php?module=mod_jaminan&act=simpan" onsubmit="return gsValidate('id_jaminan|status|catatan|jenis','ID Jaminan Harus Diisi|Status Harus Diisi|Catatan Kunjungan Harus Diisi|Jenis Kunjungan Harus Diisi','required|required|required|required');" method="post" enctype="multipart/form-data">
			<table style="margin: 10px 15px 0px 15px;">
				<tr>
					<td width="150">ID Jaminan</td>
					<td width="300">
						<input name="id_oto" type="text" id="id_oto" class="input2" value="<?php echo $newID; ?>" disabled/>
						<input name="id_jaminan" type="hidden" id="id_jaminan" class="input2" value="<?php echo $newID; ?>"/>
					</td>
				</tr>
				<tr>
					<td>ID Peserta</td>
					<td>
						<input name="id_peserta" type="text" id="id_peserta" value="<?php echo $hasil['id_peserta']; ?>" class="input2" disabled/>
						<input name="id" type="hidden" id="id" value="<?php echo $hasil['id_peserta']; ?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Nama</td>
					<td>
						<input name="nama" type="text" id="nama" value="<?php echo $hasil['nama']; ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Tempat, Tanggal Lahir</td>
					<td>
						<input name="ttl" type="text" id="ttl" value="<?php echo $hasil['tempat_lahir'].", ".tgl_ind1($hasil['tgl_lahir']); ?>" class="input2" disabled/>
					</td>
				</tr>
				<tr>
					<td>Status</td>
					<td>
						<select name="status" id="status" class="input2">
							<option value=""> - - Pilih Status - - </option>
							<option value="Baru">Baru</option>
							<option value="Perpanjang">Perpanjang</option>
						</select>
					</td>
				</tr>
			</table>
			<div id="kode_lama"></div>
			<table style="margin: 0px 15px 0px 15px;">
				<tr>
					<td width="150">Masa Berlaku :</td>
					<td width="300">
						<input type="checkbox" name="kunjungan" id="kunjungan" value="0" checked>1 Kali Kunjungan
					</td>
				</tr>
			</table>
		<div id="show">
			<table style="margin: 0px 15px 0px 15px;">
				<tr>
					<td width="150">Tanggal Mulai</td>
					<td width="300">
						<?php $tgl = date("Y-m-d"); ?>
						<input name="tgl_mulai" type="text" id="datepicker1" value="<?php echo tgl_ind1($tgl);?>" class="input2"/>
					</td>
				</tr>
				<tr>
					<td>Tanggal Selesai</td>
					<td>
						<input name="tgl_selesai" type="text" id="datepicker2" value="<?php echo tgl_ind1(tambah_tanggal($tgl,$lama['masa_berlaku']));?>" class="input2"/>
					</td>
				</tr>
			</table>
		</div>
			<table style="margin: 0px 15px 0px 15px;">
				<tr>
					<td width="150">Catatan Kunjungan</td>
					<td width="300">
						<select name="catatan" id="catatan" class="input2">
							<option value=""> - - Pilih Catatan Kunjungan - - </option>
							<?php
								$query = mysql_query("select * from catatan_kunjungan");
								while($data = mysql_fetch_array($query)){
									echo "<option value='$data[id_catatan_kunjungan]'>$data[catatan_kunjungan]</option>";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td>Jenis Kunjungan</td>
					<td>
						<select name="jenis" id="jenis" class="input2">
							<option value=""> - - Pilih Jenis Kunjungan - - </option>
							<?php
								$query = mysql_query("select * from jenis_kunjungan where id_jenis_kunjungan <> 2");
								while($data = mysql_fetch_array($query)){
									echo "<option value='$data[id_jenis_kunjungan]'>$data[jenis_kunjungan]</option>";
								}
							?>
						</select>
					</td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input name="submit" type="submit" class="button" value="Simpan" /></td>
				</tr>
			</table>                
		</form>
<?php
	}else{
?>
		<div id=tiga_ba>
			<div id=tiga_baa>Tambah Jaminan Rawat Inap</div>
			<div id=tiga_bab></div>
			<div class=clear></div>
		</div>
		<form action="utama.php?module=mod_jaminan&act=simpan_ritl" onsubmit="return gsValidate('id_jaminan|status|catatan|jenis','ID Jaminan Harus Diisi|Status Harus Diisi|Catatan Kunjungan Harus Diisi|Jenis Kunjungan Harus Diisi','required|required|required|required');" method="post" enctype="multipart/form-data">
			<table border=0>
				<tr>
					<td valign="top">
						<table style="margin: 10px 15px 0px 15px;">
							<tr>
								<td width="140">ID Jaminan</td>
								<td width="250">
									<input name="id_oto" type="text" id="id_oto" class="input2" value="<?php echo $newID; ?>" disabled/>
									<input name="id_jaminan" type="hidden" id="id_jaminan" class="input2" value="<?php echo $newID; ?>"/>
								</td>
							</tr>
							<tr>
								<td>ID Peserta</td>
								<td>
									<input name="id_peserta" type="text" id="id_peserta" value="<?php echo $hasil['id_peserta']; ?>" class="input2" disabled/>
									<input name="id" type="hidden" id="id" value="<?php echo $hasil['id_peserta']; ?>" class="input2"/>
								</td>
							</tr>
							<tr>
								<td>Nama</td>
								<td>
									<input name="nama" type="text" id="nama" value="<?php echo $hasil['nama']; ?>" class="input2" disabled/>
								</td>
							</tr>
							<tr>
								<td>Tempat, Tanggal Lahir</td>
								<td>
									<input name="ttl" type="text" id="ttl" value="<?php echo $hasil['tempat_lahir'].", ".tgl_ind1($hasil['tgl_lahir']); ?>" class="input2" disabled/>
								</td>
							</tr>
							<tr>
								<td>Status</td>
								<td>
									<select name="status" id="status" class="input2">
										<option value=""> - - Pilih Status - - </option>
										<option value="Baru">Baru</option>
										<option value="Perpanjang">Perpanjang</option>
									</select>
								</td>
							</tr>
						</table>
						<div id="kode_lama"></div>
						<table style="margin: 0px 15px 0px 15px;">
							<tr>
								<td width="140">Masa Berlaku :</td>
								<td width="250">
									<input type="checkbox" name="kunjungan" id="kunjungan" value="0" checked>1 Kali Kunjungan
								</td>
							</tr>
						</table>
					<div id="show">
						<table style="margin: 0px 15px 0px 15px;">
							<tr>
								<td width="140">Tanggal Mulai</td>
								<td width="250">
									<?php $tgl = date("Y-m-d"); ?>
									<input name="tgl_mulai" type="text" id="datepicker1" value="<?php echo tgl_ind1($tgl);?>" class="input2"/>
								</td>
							</tr>
							<tr>
								<td>Tanggal Selesai</td>
								<td>
									<input name="tgl_selesai" type="text" id="datepicker2" value="<?php echo tgl_ind1(tambah_tanggal($tgl,$lama['masa_berlaku']));?>" class="input2"/>
								</td>
							</tr>
						</table>
					</div>
						<table style="margin: 0px 15px 0px 15px;">
							<tr>
								<td width="140">Catatan Kunjungan</td>
								<td width="250">
									<select name="catatan" id="catatan" class="input2">
										<option value=""> - - Pilih Catatan Kunjungan - - </option>
										<?php
											$query = mysql_query("select * from catatan_kunjungan");
											while($data = mysql_fetch_array($query)){
												echo "<option value='$data[id_catatan_kunjungan]'>$data[catatan_kunjungan]</option>";
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Jenis Kunjungan</td>
								<td>
									<select name="jenis" id="jenis" class="input2">
										<option value=""> - - Pilih Jenis Kunjungan - - </option>
										<?php
											$query = mysql_query("select * from jenis_kunjungan where id_jenis_kunjungan = 2");
											while($data = mysql_fetch_array($query)){
												echo "<option value='$data[id_jenis_kunjungan]'>$data[jenis_kunjungan]</option>";
											}
										?>
									</select>
								</td>
							</tr>
						</table>
					</td>
					<td valign="top">
						<table style="margin: 10px 15px 0px 0px;">
							<tr>
								<td width="130">Nomer MR</td>
								<td width="310">
									<input name="mr" type="text" id="mr" class="input2"/>
								</td>
							</tr>
							<tr>
								<td>Hak Kelas Perawatan</td>
								<td>
									<select name="kelas" id="kelas" class="input2"/>
										<option value=""> - - Pilih Kelas Perawatan - - </option>
										<?php
											$kelas = mysql_query("select * from kelas_perawatan");
											while($k = mysql_fetch_array($kelas)){
												if($k['id_kelas_perawatan'] == 5){
													$s = "selected";
												}else{
													$s = "";
												}
												echo "<option value=$k[id_kelas_perawatan] $s>$k[kelas_perawatan]</option>";
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Ruang Perawatan</td>
								<td>
									<select name="ruang" id="ruang" class="input2"/>
										<option value=""> - - Pilih Ruang Perawatan - - </option>
										<?php
											$ruang = mysql_query("select * from ruang");
											while($r = mysql_fetch_array($ruang)){
												echo "<option value=$r[id_ruang]>$r[ruang]</option>";
											}
										?>
									</select>
								</td>
							</tr>
							<tr>
								<td>Perawatan : </td>
								<td align="right">
									<a href="javascript:add_data()" onclick=""><img src="asset/images/add.png"></a>
								</td>
							</tr>
							<tr>
								<td colspan="2">
									<table class="tabel2" width="100%">
										<tr>
											<th>Ruang Perawatan</th>
											<th>Tanggal Masuk</th>
											<th>Tanggal Keluar</th>
											<th></th>
										</tr>
										<tbody id="tbody_list_ruang">
										</tbody>
										
									</table>
								</td>
							</tr>
							<tr>
								<td></td>
								<td align="right"></td>
							</tr>
							<tr>
								<td>Diagnosa Awal</td>
								<td>
									<input name="diagnosa_awal" type="text" id="diagnosa_awal" class="input3"/>
								</td>
							</tr>
							<tr>
								<td>Diagnosa Keluar</td>
								<td>
									<input name="diagnosa_keluar" type="text" id="diagnosa_keluar" class="input3"/>
								</td>
							</tr>
							<tr>
								<td>Catatan Khusus</td>
								<td>
									<input name="catatan2" type="text" id="catatan" class="input3"/>
								</td>
							</tr>
						</table>
					</td>
				</tr>
				<tr>
					<td>
						<table style="margin: 10px 15px 0px 15px;">
							<tr>
								<td width="140"></td>
								<td width="250">
									<input name="submit" type="submit" class="button" value="Simpan" />
								</td>
							</tr>
						</table>
					</td>
					<td></td>
				</tr>
			</table>
		</form>
<?php
	}
?>